﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;


namespace Xiaov.SmartWeb.Application.HXZB
{
    public partial class SczbLeftDownData : System.Web.UI.Page
    {
        string dwbm = "", nf = "", yf = "", zbbm = "", type = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                #region 获取参数
                if (Request.QueryString["zbbm"] != null)
                {
                    zbbm = Request.QueryString["zbbm"].ToString();
                }
                if (Request.QueryString["dwbm"] != null)
                {
                    dwbm = Request.QueryString["dwbm"].ToString();
                }
                if (Request.QueryString["nf"] != null && Request.QueryString["yf"] != null)
                {
                    nf = Request.QueryString["nf"].ToString();
                    yf = Request.QueryString["yf"].ToString();
                }
                if (Request.QueryString["type"] != null)//数据信息 标题，本年数据，去年数据
                {
                    type = Request.QueryString["type"].ToString();
                }
                #endregion
                DataSet ds = null;
                switch (zbbm)
                {                  
                    #region 原油
                    case "TG030008":  //
                        zbbm = "SC010001";
                        ds = InitRight("sc01", "bnlj");
                        break;
                    #endregion
                    #region 天然气
                    case "TG030026":  //
                        zbbm = "SC010003";
                        ds = InitRight("sc01", "bnlj");
                        break;
                    #endregion
                    #region 凝析油
                    case "TG030012":  //
                        zbbm = "SC010002";
                        ds = InitRight("sc01", "bnlj");
                        break;
                    #endregion
                    #region 销售量原油
                    case "TG030015":  //
                        zbbm = "SC030008";
                        ds = InitRight("sc03", "bnlj");
                        break;
                    #endregion
                    #region 销售量天然气
                    case "TG030031":  //
                        zbbm = "SC030016";
                        ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    #region 原油配置量
                    case "TG030016":  //
                       // ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    #region 供石化
                    case "TG030018":  //
                       // ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    #region 地方炼油企业
                    case "TG030019":  //
                       // ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    #region 地方小炼厂
                    case "TG030020":  //
                      //  ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    #region 损耗量原油
                    case "TG030023":  //
                        zbbm = "SC030009";
                        ds = InitRight("sc03", "bnlj");
                        break;
                    #endregion
                    #region 损耗量天然气
                    case "TG030041":  //
                        zbbm = "SC030018";
                        ds = InitRight("tg03", "bnlj");
                        break;
                    #endregion
                    default:
                        break;
                }
                #region 输出数据
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["bnlj"].ToString() == "")
                        {
                            ds.Tables[0].Rows[i]["bnlj"] = 0;
                        }
                        if (type == "title")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["dwmc"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["dwmc"].ToString());
                            }
                        }
                        else if (type == "data")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString());
                            }
                        }
                    }
                    Response.End();
                }
                #endregion               
            }
        }

        /// <summary>
        /// 获取图形数据
        /// </summary>
        /// <param name="bbbm">报表编码</param>
        /// <param name="zdmc">字段名称</param>
        protected DataSet InitRight(string bbbm, string zdmc)
        {
            DataSet ds = null;
            StringBuilder sbSql = new StringBuilder();
            sbSql.AppendFormat(@"select a.{0},b.dwmc from {1} a,dwbmb b where a.dwbm=b.dwbm and a.nf={2} and a.yf={3} and a.zbbm='{4}' and a.dwbm in ({5})", 
                zdmc, bbbm, nf, yf, zbbm, "'HB01','HB02','HB03','HB04','HB05'");
            ds = Maticsoft.DBUtility.DbHelperOra.Query(sbSql.ToString());
            return ds;
        }
    }
}